//
//  SentryHelper.swift
//  ezyform
//
//  Created by Moennig Q on 11/8/2022.
//  Copyright © 2022 Client.Solution Pty Ltd. All rights reserved.
//

import Foundation
import Sentry
class SentryHelper {
    func launchSentry(){
        //Crashlytics
        SentrySDK.start { options in
            options.dsn = APPConfig.SentryDSN
            options.debug = false // Enabled debug when first installing is always helpful
            // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
            // We recommend adjusting this value in production.
            options.tracesSampleRate = 0.01
            options.environment = APPConfig.isTestFlag ? "dev" : "production"
        }
    }
    //设置crash 日志自定义信息
    func setCrashLogCustomInfo(pvdId: Int64? = nil, gwtNo: String? = nil){
        let user = User()
        user.email = APPConfig.loginInfo.email
        user.data = [
                         "environment": APPConfig.isTestFlag ? "Staging": "Production",//区分是哪个环境报的错误
                         "User Full Name": APPConfig.loginInfo.fullName,
                         "PVD ID" : pvdId ?? 0,
                         "GWT NO" : gwtNo ?? ""
                        ] as [String : Any]
        SentrySDK.setUser(user)
    }
    func captureCustomLog(_ msg: String){
        SentrySDK.capture(message: msg)
    }
    deinit{
        if APPConfig.isTestFlag{
            debugPrint("SentryHelper deinit")
        }
    }
}
    
